using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for ControlReader
/// </summary>
public class ControlReader
{
    PageCommonFunctions PCF = new PageCommonFunctions();
    DynamicDisplayI DDI = new DynamicDisplayI();
    public string errormessage = "";
    public ControlReader()
    {
        //
        // TODO: Add constructor logic here
        //
    }

    public string CaptureCtrlData(DataRow droPageCtrl, DataTable dtaPage, DataTable dtaPageKeys, HtmlForm frmObj,
        DataSet dsePageInputInfo, DataTable dtaPageCtrl, int intPageSeq, bool blnMultiplePage, int intCurrentRow,bool requiredfield)
    {
        Localization loc = new Localization();
        string strRet = "";
        /////string strCtrlId = droPageCtrl["control_id"].ToString();
        /////j
        string strCtrlId = droPageCtrl["control_attrib_id"].ToString();
        string strPageId = droPageCtrl["page_id"].ToString();
        DataRow[] drr = dtaPage.Select("af_row_id='" + strPageId + "'");
        if (drr.Length > 0)
            strPageId = drr[0]["page_id"].ToString();
        string strCtrlType = droPageCtrl["control_html"].ToString();
        string strCtrlColumn = droPageCtrl["control_attrib_id"].ToString();
        string strActualCtrlID = droPageCtrl["control_attrib_id"].ToString();
        string strBindRowID = droPageCtrl["control_bind_id"].ToString();
        /////j
        strCtrlId = strCtrlColumn;
        /*if (PCF.IsParentPageKeyControl(strCtrlColumn, dtaPage, dtaPageKeys, intPageSeq))
        {
            //Take the value from the previous page
            strRet = PCF.FindInputValue(dsePageInputInfo, dtaPage.Rows[intPageSeq - 1]["page_id"].ToString(), strCtrlColumn, dtaPageCtrl);
        }
        else
        {*/
            strCtrlId = strPageId + "_" + strCtrlId;
            if (blnMultiplePage)
            {
                strCtrlId += "_" + intCurrentRow.ToString();
            }
            //if (strCtrlId.IndexOf("af_row_id") > -1)
            if (!Convert.ToBoolean(droPageCtrl["control_visible"].ToString() == "" ? "false" : droPageCtrl["control_visible"].ToString()))
            {
                #region transdocHidden
                //Control con = DDI.FindControl(frmObj.Controls, strCtrlId);
                //if (con is TextBox) // Added for Transaction Document page
                //{
                //    TextBox txtObj = (TextBox)con;
                //    if (txtObj != null)
                //    {
                //        strRet = txtObj == null ? "" : txtObj.Text;//changed by sanal original code: strRet = txtObj.Text
                //    }
                //}
                //else
                //{
#endregion

                    HiddenField txtObj = (HiddenField)DDI.FindControl(frmObj.Controls, strCtrlId);//TextBox txtObj = (TextBox)frmObj.FindControl(strCtrlId);
                    if (txtObj != null)
                    {
                        strRet = txtObj == null ? "" : txtObj.Value;//changed by sanal original code: strRet = txtObj.Text
                    }
                //}
                return strRet;
            }
            switch (strCtrlType.ToUpper())
            {
                case "DA":
                case "DT":
                    /*C1WebDateEdit C1txtObj = new C1WebDateEdit();
                    if (droPageCtrl["control_id"].ToString() == GlobalValues.ModifiedDate) // modifed date default to current date irrespective of page control settings
                    {
                        C1txtObj.Text = DateTime.Now.ToString();
                    }
                    strRet = C1txtObj.Text;
                    break;*/
                case "AN":
                case "TB":
                case "EM":
                    TextBox txtObj;
                    if (droPageCtrl["control_bind_id"].ToString() != "")  // Added by srivatsan for bind changes for text box on July 16 2009
                    {
                        HiddenField hfobj = (HiddenField)DDI.FindControl(frmObj.Controls, strCtrlId);
                        txtObj = (TextBox)DDI.FindControl(frmObj.Controls,"txt_"+strCtrlId);

                        if (hfobj != null)
                        {

                            //if (droPageCtrl["control_attrib_id"].ToString() == "owner_id")
                            //{
                            //    if (txtObj.Text == "")
                            //    {
                            //        errormessage = "Owner cannot be empty";
                            //    }

                            //}

                            BindControl BC = new BindControl();
                            HDDatabase HDD = new HDDatabase();
                            DataSet dsBind = new DataSet();
                            string data = txtObj.Text;

                            string sql = BC.GetBindSql(droPageCtrl["control_bind_id"].ToString());
                            dsBind = HDD.GetDataset(sql);

                            //string bindafrowid = HDD.GetColumnValue("select af_row_id from sy_bnd where af_row_id ='"+droPageCtrl["control_bind_id"].ToString()+"'");
                            if (droPageCtrl["control_bind_id"].ToString() == "f496930dfe0b690f" && (txtObj.Text.Trim() == "" || txtObj.Text.Trim() == HttpContext.Current.Session["userid"].ToString()))
                            {
                                if (txtObj.Text.Trim() == "")
                                {
                                    if(txtObj.Enabled == false && hfobj.Value == HttpContext.Current.Session["user_afrowid"].ToString())
                                    {
                                        txtObj.Text = HttpContext.Current.Session["userid"].ToString();
                                        hfobj.Value = HttpContext.Current.Session["user_afrowid"].ToString();
                                        strRet = txtObj.Text;
                                    }
                                    else if (txtObj.Enabled == false)
                                    {
                                        if (dsBind != null)
                                        {
                                            if (dsBind.Tables.Count > 0)
                                            {
                                                if (dsBind.Tables[0].Rows.Count > 0)
                                                {
                                                    if (hfobj.Value != "")
                                                    {
                                                        DataRow[] drrdata = dsBind.Tables[0].Select("val = '" + hfobj.Value + "'");
                                                        if (drrdata.Length > 0)
                                                        {
                                                            string displayvalue = drrdata[0]["fld"].ToString();

                                                            txtObj.Text = displayvalue;
                                                            hfobj.Value = drrdata[0]["val"].ToString();
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        strRet = txtObj.Text;
                                        hfobj.Value = "";
                                    }

                                    
                                }
                                else if (txtObj.Text.Trim() == HttpContext.Current.Session["userid"].ToString())
                                {
                                    strRet = txtObj.Text;
                                    hfobj.Value = HttpContext.Current.Session["user_afrowid"].ToString();
                                }
                            }
                            else
                            {
                                if (dsBind != null)
                                {
                                    if (dsBind.Tables.Count > 0)
                                    {
                                        if (dsBind.Tables[0].Rows.Count > 0)
                                        {
                                            #region Old code commented by 'Imran Gani' on 28-Feb-2014, for MBLocale
                                            //if (droPageCtrl["control_attrib_type"].ToString() == "NU" || droPageCtrl["control_attrib_type"].ToString() == "AN" || droPageCtrl["control_attrib_type"].ToString() == "FL")
                                            //{
                                            //    if (data.Trim() != "")
                                            //    {
                                            //        string result = "";
                                            //        try
                                            //        {
                                            //            switch (droPageCtrl["control_attrib_type"].ToString())
                                            //            {
                                            //                case "NU":
                                            //                case "AN":
                                            //                    result = Convert.ToInt32(data).ToString();
                                            //                    break;
                                            //                case "FL":
                                            //                case "DC":
                                            //                case "CU":
                                            //                    result = Convert.ToDouble(data).ToString();
                                            //                    break;
                                            //                default:
                                            //                    break;

                                            //            }
                                            //        }
                                            //        catch
                                            //        {
                                            //            result = "";
                                            //        }
                                            //        if (result != "")
                                            //        {
                                            //            drrbind = dsBind.Tables[0].Select("fld = " + data.Replace("'","''") + "");
                                            //        }
                                            //        else
                                            //        {
                                            //            errormessage = "Invalid data for " + droPageCtrl["control_name"].ToString() + ": " + data + "";
                                            //            strRet = hfobj == null ? "" : hfobj.Value;
                                            //        }
                                            //    }
                                            //}
                                            //else
                                            //{
                                            //    if (data.Trim() != "")
                                                
                                            //        try
                                            //        {
                                            //            drrbind = dsBind.Tables[0].Select("fld = '" + data.Replace("'","''") + "'");
                                            //        }
                                            //    catch{ 
                                            
                                            //    errormessage = "Invalid data for " + droPageCtrl["control_name"].ToString() + ": " + data + "";
                                            
                                                
                                                
                                            //    }
                                            //}
                                            #endregion

                                            #region New code added by 'Imran Gani' on 28-Feb-2014, for MBLocale
                                            BC.HandleLocalizedBindText(dsBind.Tables[0], droPageCtrl["control_bind_id"].ToString());
                                            DataRow[] drrbind = null;
                                            if (data.Trim() != "")
                                            {
                                                try
                                                {
                                                    drrbind = dsBind.Tables[0].Select("fld = '" + data.Replace("'", "''") + "'");
                                                }
                                                catch
                                                {
                                                    errormessage = "Invalid data for " + droPageCtrl["control_name"].ToString() + ": " + data + "";
                                                    strRet = hfobj == null ? "" : hfobj.Value;
                                                }
                                            }
                                            #endregion
                                            if (drrbind != null)
                                            {
                                                if (drrbind.Length == 0)
                                                {
                                                    if (requiredfield)
                                                    {
                                                        errormessage = "Invalid data for " + droPageCtrl["control_name"].ToString() + ": " + data + "";
                                                    }
                                                    else
                                                    {
                                                        if (txtObj.Text != "")
                                                        {
                                                            errormessage = "Invalid data for " + droPageCtrl["control_name"].ToString() + ": " + data + "";
                                                        }
                                                        else
                                                        {
                                                            //if (droPageCtrl["control_attrib_id"].ToString().ToLower() == "owner_id")
                                                            //{
                                                            hfobj.Value = "";
                                                            //}
                                                            ////else
                                                            //{
                                                            //errormessage = "Invalid data for " + droPageCtrl["control_name"].ToString() + ": " + data + "";
                                                            //}
                                                        }
                                                        strRet = hfobj == null ? "" : hfobj.Value;

                                                    }


                                                }
                                                else
                                                {
                                                    hfobj.Value = drrbind[0]["val"].ToString();
                                                    strRet = hfobj == null ? "" : drrbind[0]["val"].ToString();
                                                }
                                            }
                                            else
                                            {
                                                //if (data != "")
                                                //{
                                                //    errormessage = "Invalid data for " + droPageCtrl["control_name"].ToString() + ": " + data + "";
                                                //}
                                                //else
                                                //{
                                                    hfobj.Value = "";
                                                    strRet = "";
                                                //}
                                            }
                                        }
                                        else
                                        {
                                            if (data != "")
                                            {
                                                errormessage = "Invalid data for " + droPageCtrl["control_name"].ToString() + ": " + data + "";
                                            }
                                            else
                                            {
                                                hfobj.Value = "";
                                                strRet = "";
                                            }
                                        }
                                    }
                                }
                            }


                            if (droPageCtrl["control_attrib_id"].ToString() == GlobalValues.ModifiedDate)/////if (droPageCtrl["control_id"].ToString() == GlobalValues.ModifiedDate) // modifed date default to current date irrespective of page control settings
                            {
                                hfobj.Value = DateTime.Now.ToUniversalTime().ToString();
                            }

                            #region Old code commented by 'Imran Gani' on 28-Feb-2014, to avoid 'if' statement and to use switch case
                            //if (droPageCtrl["control_attrib_type"].ToString() == "DA")//included by sanal on 03 sept 2008
                            //{
                            //    if (hfobj.Value.Trim() == "")
                            //        strRet = hfobj.Value;
                            //    else
                            //    {
                            //        Localization ll = new Localization();
                            //        strRet = ll.getInvariantDate(hfobj.Value);
                            //        ll = null;
                            //    }
                            //}
                            //else if (droPageCtrl["control_attrib_type"].ToString() == "DT")//included by sanal on 03 sept 2008
                            //{
                            //    if (hfobj.Value.Trim() == "")
                            //        strRet = hfobj.Value;
                            //    else
                            //    {
                            //        Localization ll = new Localization();
                            //        strRet = ll.getDateTime4TimeZone(hfobj.Value, DDI.getUserSetting("sy_usr", "time_zone", "sy_timezone", "utc_offset", "timezone_id"), true, false);
                            //        ll = null;
                            //    }
                            //}
                            //else if (droPageCtrl["control_attrib_type"].ToString() == "CU")//included by sanal on 03 sept 2008
                            //{
                            //    if (hfobj.Value.Trim() == "")
                            //        strRet = hfobj.Value;
                            //    else
                            //    {
                            //        strRet = manageCurrencyInput(hfobj.Value);
                            //    }
                            //}
                            //else
                            //    strRet = hfobj == null ? "" : hfobj.Value;//changed by sanal original code: strRet = txtObj.Text
                            #endregion
                            if (hfobj != null)
                                strRet = loc.getDBValueFromLocale(hfobj.Value.Trim(), droPageCtrl["control_attrib_type"].ToString()); // Added by 'Imran Gani' on 28-Feb-2014, for MBLocale
                        }
                        else
                        {
                            strRet = txtObj == null ? "" : txtObj.Text;
                        }
                    

                    }
                    else
                    {

                        string masterattrib_id = "";
                        DataRow[] drrmasterlinkfield = null;
                        if(dtaPageKeys.Rows.Count>0)
                        {
                            drrmasterlinkfield = dtaPageKeys.Select("attrib_id = '"+strActualCtrlID+"'");
                            if (drrmasterlinkfield.Length > 0)
                            {
                                masterattrib_id = drrmasterlinkfield[0]["attrib_id"].ToString().ToLower();
                               // masterattrib_id = dtaPageKeys.Rows[0]["attrib_id"].ToString().ToLower();
                            }
                    
                        }
                        
                                if (strActualCtrlID.ToLower() == masterattrib_id.ToLower())
                                {
                                    Control cn = DDI.FindControl(frmObj.Controls, strCtrlId);

                                    if (cn is HiddenField)
                                    {
                                        HiddenField hf = (HiddenField)cn;
                                        txtObj = (TextBox)DDI.FindControl(frmObj.Controls, "txt_" + strCtrlId);
                                        if (txtObj.Text != "")
                                        {
                                            string strTableName = "";
                                            string bindfield = "";
                                            string sMSFieldDataType = ""; // Added by 'Imran Gani' on 28-Feb-2014, for MBLocale
                                            if (dtaPageKeys != null)
                                            {
                                                if (dtaPageKeys.Rows.Count > 0)
                                                {
                                                    HDDatabase HDD = new HDDatabase();
                                                    string masterobj = dtaPageKeys.Rows[0]["master_obj"].ToString();
                                                    bindfield = dtaPageKeys.Rows[0]["display_att"].ToString();
                                                    strTableName = HDD.GetColumnValue("sy_obj", "object_table", "object_id='" + masterobj + "'");
                                                    sMSFieldDataType = HDD.GetColumnValue("select attrib_data_type from sy_obj_att where object_id = (select af_row_id from sy_obj where object_id = '" + masterobj + "') and attrib_id = '" + bindfield + "';");
                                                    HDD = null;
                                                }
                                            }
                                            if (strTableName != "")
                                            {
                                                txtObj.Text = loc.getDBValueFromLocale(txtObj.Text.Trim(), sMSFieldDataType); // Added by 'Imran Gani' on 28-Feb-2014, for MBLocale

                                                MasterDetail MD = new MasterDetail();
                                                DataTable dtaMaster = MD.GetMasterDataFromValue(strTableName, txtObj.Text, bindfield);

                                                if (dtaMaster != null)
                                                {
                                                    if (dtaMaster.Rows.Count > 0)
                                                    {
                                                        if (hf.Value != "")
                                                        {
                                                            DataRow[] drselect = dtaMaster.Select("af_row_id='" + hf.Value + "'");
                                                            if (drselect.Length > 0)
                                                            {
                                                                txtObj.Text = drselect[0][bindfield].ToString();
                                                                hf.Value = drselect[0]["af_row_id"].ToString();
                                                            }
                                                            else
                                                            {
                                                                txtObj.Text = dtaMaster.Rows[0][bindfield].ToString();
                                                                hf.Value = dtaMaster.Rows[0]["af_row_id"].ToString();
                                                                
                                                            }
                                                        }
                                                        else
                                                        {
                                                            txtObj.Text = dtaMaster.Rows[0][bindfield].ToString();
                                                            hf.Value = dtaMaster.Rows[0]["af_row_id"].ToString();
                                                        }
                                                    }
                                                    else
                                                    {
                                                        errormessage = "Invalid data for " + droPageCtrl["control_name"].ToString() + " :" + txtObj.Text;
                                                        hf.Value = "";
                                                    }
                                                }

                                            }




                                            strRet = hf.Value;
                                        }
                                    }
                                }
                            
                        
                        else
                        {

                            txtObj = (TextBox)DDI.FindControl(frmObj.Controls, strCtrlId);//TextBox txtObj = (TextBox)frmObj.FindControl(strCtrlId);
                            if (txtObj != null)
                            {
                                if (droPageCtrl["control_attrib_id"].ToString() == GlobalValues.ModifiedDate)/////if (droPageCtrl["control_id"].ToString() == GlobalValues.ModifiedDate) // modifed date default to current date irrespective of page control settings
                                {
                                    txtObj.Text = DateTime.Now.ToUniversalTime().ToString();
                                }

                                #region Old code commented by 'Imran Gani' on 28-Feb-2014, to avoid 'if' statement and to use switch case
                                //if (droPageCtrl["control_attrib_type"].ToString() == "DA")//included by sanal on 03 sept 2008
                                //{
                                //    if (txtObj.Text.Trim() == "")
                                //        strRet = txtObj.Text;
                                //    else
                                //    {
                                //        Localization ll = new Localization();
                                //        strRet = ll.getInvariantDate(txtObj.Text);
                                //        ll = null;
                                //    }
                                //}
                                //else if (droPageCtrl["control_attrib_type"].ToString() == "DT")//included by sanal on 03 sept 2008
                                //{
                                //    if (txtObj.Text.Trim() == "")
                                //        strRet = txtObj.Text;
                                //    else
                                //    {
                                //        Localization ll = new Localization();
                                //        strRet = ll.getDateTime4TimeZone(txtObj.Text, DDI.getUserSetting("sy_usr", "time_zone", "sy_timezone", "utc_offset", "timezone_id"), true, false);
                                //        ll = null;
                                //    }
                                //}
                                //else if (droPageCtrl["control_attrib_type"].ToString() == "CU")//included by sanal on 03 sept 2008
                                //{
                                //    if (txtObj.Text.Trim() == "")
                                //        strRet = txtObj.Text;
                                //    else
                                //    {
                                //        strRet = manageCurrencyInput(txtObj.Text);
                                //    }
                                //}
                                //else
                                //    strRet = txtObj == null ? "" : txtObj.Text;//changed by sanal original code: strRet = txtObj.Text
                                #endregion

                                strRet = loc.getDBValueFromLocale(txtObj.Text.Trim(), droPageCtrl["control_attrib_type"].ToString()); // Added by 'Imran Gani' on 28-Feb-2014, for MBLocale
                            }
                        }
                    }
                    break;
                case "PW":
                case "ENC":
                    txtObj = (TextBox)DDI.FindControl(frmObj.Controls, strCtrlId);//TextBox txtObj = (TextBox)frmObj.FindControl(strCtrlId);
                    if (txtObj != null)
                    {
                        if (droPageCtrl["control_attrib_id"].ToString() == GlobalValues.ModifiedDate)/////if (droPageCtrl["control_id"].ToString() == GlobalValues.ModifiedDate) // modifed date default to current date irrespective of page control settings
                        {
                            txtObj.Text = DateTime.Now.ToUniversalTime().ToString();
                        }
                        strRet = txtObj == null ? "" : security.encrypt(txtObj.Text);//changed by sanal original code: strRet = txtObj.Text
                    }
                    break;
                case "TA":
                    txtObj = (TextBox)DDI.FindControl(frmObj.Controls, strCtrlId);//TextBox txtObj = (TextBox)frmObj.FindControl(strCtrlId);
                    if (txtObj != null)
                    {
                        if (droPageCtrl["control_attrib_id"].ToString() == GlobalValues.ModifiedDate) // modifed date default to current date irrespective of page control settings
                        {
                            txtObj.Text = DateTime.Now.ToString();
                        }
                        strRet = txtObj == null ? "" : txtObj.Text;//changed by sanal original code: strRet = txtObj.Text
                    }
                    break;
                case "CB":
                    CheckBox cbObj = (CheckBox)DDI.FindControl(frmObj.Controls, strCtrlId);//CheckBox cbObj = (CheckBox)frmObj.FindControl(strCtrlId);
                    if (cbObj != null)
                        strRet = cbObj == null ? "False" : cbObj.Checked.ToString();//changed by sanal
                    break;
                case "DD":
                case "DDE":
                    Control ddcon = DDI.FindControl(frmObj.Controls, strCtrlId);
                    if (ddcon != null)
                    {
                        if (ddcon is HiddenField)
                        {
                           HiddenField hfmaster = (HiddenField)DDI.FindControl(frmObj.Controls, strCtrlId);
                           strRet = hfmaster.Value;
                        }
                        else
                        {
                            DropDownList ddlObj = (DropDownList)DDI.FindControl(frmObj.Controls, strCtrlId); //DropDownList ddlObj = (DropDownList)frmObj.FindControl(strCtrlId);
                            if (ddlObj != null)
                            {
                                if (strCtrlType.ToUpper() == "DDE") // Added by srivatsan for DDE change 
                                {
                                    if (strBindRowID != "")
                                    {
                                        BindControl BC = new BindControl();
                                        HDDatabase HDD = new HDDatabase();
                                        string sql = BC.GetBindSql(strBindRowID);
                                        if (sql.Trim() != "")
                                        {
                                            DataTable dt = HDD.GetDataTable(sql);
                                            if(dt!=null)
                                                //if (dt.Rows.Count > 0)
                                                {
                                                    string ddedisplay = GetDisplayText(ddlObj);
                                                    if (ddedisplay.Trim() != "")
                                                    {
                                                        DataRow[] drrdata = null;
                                                        try
                                                        {
                                                            drrdata = dt.Select("fld = '" + ddedisplay.Trim() + "'");
                                                        }
                                                        catch
                                                        {
                                                            drrdata = dt.Select("val = '"+ddlObj.SelectedValue+"'");
                                                        }
                                                        if(drrdata!=null)
                                                        {

                                                            if (drrdata.Length > 0)
                                                            {
                                                                strRet = drrdata[0]["val"].ToString();
                                                            }
                                                            else
                                                            {
                                                                int index = ddlObj.Items.IndexOf(ddlObj.Items.FindByText(ddedisplay));
                                                                ddlObj.SelectedIndex = index;
                                                                errormessage = "Invalid data for " + droPageCtrl["control_name"].ToString() + ": " + ddedisplay + "";
                                                                strRet = "";
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        strRet = ddlObj == null ? "" : ddlObj.SelectedValue;//changed by sanal
                                                    }
                                                }
                                        }
                                        BC = null;
                                        HDD = null;
                                    }
                                }
                                else
                                    strRet = ddlObj == null ? "" : ddlObj.SelectedValue;//changed by sanal
                            }
                        }
                    }
                        break;
                case "DL": // Added by 'Imran Gani' on 26-Dec-2013, for droplist support.
                        Control dlcon = DDI.FindControl(frmObj.Controls, strCtrlId);
                        if (dlcon != null)
                        {
                            if (dlcon is HiddenField)
                            {
                                HiddenField hfmaster = (HiddenField)DDI.FindControl(frmObj.Controls, strCtrlId);
                                strRet = hfmaster.Value;
                            }
                            else
                            {
                                DropDownList ddlObj = (DropDownList)DDI.FindControl(frmObj.Controls, strCtrlId);
                                strRet = ddlObj == null ? "" : ddlObj.SelectedValue;
                            }
                        }
                        break;
            }
        //}
        return strRet;
    }

    #region Old code commented by 'Imran Gani' on 28-Feb-2014, for MBLocale
    //private string manageCurrencyInput(string input)
    //{
    //    if (input == "") return "";
    //    string ret="";
    //    Localization ll = new Localization();
    //    double temp = 0.0;
    //    try
    //    {
    //        temp = Convert.ToDouble(input);
    //        ret = input;//parsing was successfull
    //    }
    //    catch (Exception e)
    //    {
    //        try
    //        {
    //            temp = double.Parse(input, ll.getUserCulture());
    //            ret = temp.ToString();
    //        }
    //        catch (Exception ee)
    //        {
    //            ret = input;
    //        }
    //    }
    //    ll = null;
    //    return ret;
    //}
    #endregion

    private string GetDisplayText(DropDownList DDL)
    {
        string result = DDL.SelectedItem.Text;
        try
        {
            //commented for getting data from hiddenfield.
            if (DDL.SelectedItem.Value.Trim() != "")
            {
                return result;
            }
            if(DDL.Page!=null)
                if(DDL.Page.Request!=null)
                    if (DDL.Page.Request.Form != null)
                    {
                        string id = "ctl00$ContentPlaceHolder3$hf_DDE_DV_"+DDL.ID;

                        HiddenField hf = (HiddenField)DDI.FindControl(DDL.Page.Form.Controls,"hf_DDE_DV_"+DDL.ID);
                        if (hf != null)
                        {
                            result = hf.Value;
                            #region Get Value based on DataType
                            //if (strDataType.ToUpper() == "DA")
                                //{
                                //    if (hf.Value == "")
                                //        result = hf.Value;
                                //    else
                                //    {
                                //        Localization ll = new Localization();
                                //        result = ll.getInvariantDate(hf.Value);
                                //        ll = null;
                                //    }
                                //}
                                //else if (strDataType.ToUpper() == "DT")
                                //{
                                //    if (hf.Value == "")
                                //        result = hf.Value;
                                //    else
                                //    {
                                //        Localization ll = new Localization();
                                //        result = ll.getDateTime4TimeZone(hf.Value, DDI.getUserSetting("sy_usr", "time_zone", "sy_timezone", "utc_offset", "timezone_id"), true, false);
                                //        ll = null;
                                //    }
                                //}
                                //else
                                //{
                                //    result = hf.Value;
                            //}
                            #endregion
                        }
                        else
                        {
                            if (DDL.Page.Request.Form[id].ToString() != "")
                            {
                                result = DDL.Page.Request.Form[id].ToString();
                            }
                        }
                        
                    }
        }
        catch(Exception ex)
        {
            LogWriter.WriteLog("Error : GetDisplayText: "+ ex.Message);
        }
        return result;
    }
}

